package com.handinfo.android.ui.window;

import java.io.DataInputStream;
import java.io.IOException;
import java.util.concurrent.CopyOnWriteArrayList;

import android.graphics.Bitmap;

import com.handinfo.android.DWGameManager;
import com.handinfo.android.game.GameMessage;
import com.handinfo.android.game.item.Tianming;
import com.handinfo.android.ui.IUIWindows;
import com.handinfo.android.ui.UIWindows;
import com.handinfo.android.uicontrols.DWControlTools;
import com.handinfo.android.uicontrols.DWControlsManager;
import com.handinfo.android.uicontrols.DWDragListener;
import com.handinfo.android.uicontrols.DWListener;
import com.handinfo.android.uicontrols.controls.DWBackground;
import com.handinfo.android.uicontrols.controls.DWButton;
import com.handinfo.android.uicontrols.controls.DWControl;
import com.handinfo.android.uicontrols.controls.DWFrame;
import com.handinfo.android.uicontrols.controls.DWGrid;
import com.handinfo.android.uicontrols.controls.DWGrids;
import com.handinfo.android.uicontrols.controls.DWImageBox;
import com.handinfo.android.uicontrols.controls.DWMessageBox;
import com.handinfo.android.uicontrols.controls.DWTextbox;
import com.handinfo.android.uicontrols.controls.DWTitle;
import com.handinfo.android.utils.Tools;

/**
 * 
 * 祭命台界面
 * 天命
 * 
 * @author mujianchen
 * 
 */

public class UIJiMingTai implements IUIWindows
{
	public DWFrame m_jmtFrame01 = null;
	public DWFrame m_jmtFrame02 = null;
	public DWTitle m_jmtTitle01 = null;
	public DWTitle m_jmtTitle02 = null;

	public DWImageBox m_jmtImageBox01 = null;//关闭按钮01
	public DWImageBox m_jmtImageBox02 = null;//关闭按钮02

	public DWImageBox m_jmtImageBox_BT01 = null;//标题祭天
	public DWImageBox m_jmtImageBox_BT02 = null;//标题天命

	//神龛
	public DWButton m_jmtButton03 = null;
	public DWButton m_jmtButton04 = null;
	public DWButton m_jmtButton05 = null;
	public DWButton m_jmtButton06 = null;
	public DWButton m_jmtButton07 = null;

	//背景
	public DWBackground m_jmtBackground01 = null;

	public DWBackground m_jmtBackground_jttBJ = null;//第一界面背景
	public DWButton m_jmtButton_jttBT01 = null;//装备天命
	public DWButton m_jmtButton_jttBT02 = null;//连续拜祭
	public DWButton m_jmtButton_jttBT03 = null;//自动吞噬
	public DWButton m_jmtButton_jttBT04 = null;//全部收取

	public DWButton m_jmtButton_tmtBT01 = null;//返回第一界面

	//文本框
	public DWTextbox m_jmtTextbox01 = null;
	public DWTextbox m_jmtTextbox02 = null;

	public DWTextbox m_jmtTextbox06 = null;//显示命力界面1
	public DWTextbox m_jmtTextbox07 = null;//显示金钱界面1

	public DWTextbox m_jmtTextbox08 = null;//显示命力界面2
	public DWTextbox m_jmtTextbox09 = null;//显示金钱界面2

	//图片
	public Bitmap m_jmtBitmap01 = null;

	public Bitmap m_jmtBitmap_BT01 = null;//标题祭天图片
	public Bitmap m_jmtBitmap_BT02 = null;//标题天命图片

	//装备天命图片
	public Bitmap m_jmtBitmap_ZBTM = null;

	public Bitmap m_jmtBitmap08 = null;//背包锁

	//装备位
	public DWGrid[] m_jmtGrid11 = new DWGrid[8];

	public static Bitmap[] m_jmtBitmap03 = new Bitmap[11];//天命图标

	public Bitmap m_jmtBitmap10 = null;
	public Bitmap[] m_jmtBitmap11 = new Bitmap[5];//神龛亮
	public Bitmap[] m_jmtBitmap16 = new Bitmap[5];//神龛暗

	public Bitmap m_jmtBitmap21 = null;
	public Bitmap m_jmtBitmap22 = null;

	public Bitmap m_jmtBitmap21_xia = null;
	public Bitmap m_jmtBitmap22_xia = null;

	//第一界面下边问题提示
	public DWTextbox m_jmtTextbox_TS = null;

	public int bbsize01;

	//祭拜结果显示
	public DWTextbox m_tgTextbox_JBJG = null;

	//网格锁
	//背包开启格
	public DWGrids m_tGrids02 = null;

	public DWGrids m_tGrids01 = null;//祭天台界面网格

	public int whi;

	public byte j;

	//未装备下标对象
	public int tianming_index01 = 0;
	//装备下标对象
	public int tianming_index02 = 0;

	//天命背包一次开启个数
	public int tianmingBao_Num = 0;

	//第一界面grids下标
	public int tianming_index03 = 0;

	//拖拽下标(gtids)
	public int tuozhuai_index02 = 0;

	//开启窗口判断
	public int open_state = 0;

	//关闭窗口判断
	public int close_state = 0;

	//是否第一次开启天命第二界面
	public boolean frist_open_state02 = false;

	public void init()
	{
		m_jmtBitmap01 = UIWindows.createImage("/img/newui/fanhuianniu_1.gnp");

		//标题
		m_jmtBitmap_BT01 = UIWindows.createImage("/img/newui/jitian.gnp");
		m_jmtBitmap_BT02 = UIWindows.createImage("/img/newui/tianming.gnp");

		m_jmtBitmap03[0] = UIWindows.createImage("/img/icon/big_datubiao_212.gnp");
		m_jmtBitmap03[1] = UIWindows.createImage("/img/icon/big_datubiao_213.gnp");
		m_jmtBitmap03[2] = UIWindows.createImage("/img/icon/big_datubiao_214.gnp");
		m_jmtBitmap03[3] = UIWindows.createImage("/img/icon/big_datubiao_215.gnp");
		m_jmtBitmap03[4] = UIWindows.createImage("/img/icon/big_datubiao_216.gnp");
		m_jmtBitmap03[5] = UIWindows.createImage("/img/icon/big_datubiao_217.gnp");
		m_jmtBitmap03[6] = UIWindows.createImage("/img/icon/big_datubiao_218.gnp");
		m_jmtBitmap03[7] = UIWindows.createImage("/img/icon/big_datubiao_219.gnp");
		m_jmtBitmap03[8] = UIWindows.createImage("/img/icon/big_datubiao_220.gnp");
		m_jmtBitmap03[9] = UIWindows.createImage("/img/icon/big_datubiao_221.gnp");
		m_jmtBitmap03[10] = UIWindows.createImage("/img/icon/big_datubiao_222.gnp");

		m_jmtBitmap10 = UIWindows.createImage("/img/newui/wupinlan.gnp");//网格
		m_jmtBitmap08 = UIWindows.createImage("/img/newui/beibaost_1.gnp");//网格锁

		//神龛亮
		m_jmtBitmap11[4] = UIWindows.createImage("/img/newui/jimingtaisxtd_1.gnp");
		m_jmtBitmap11[3] = UIWindows.createImage("/img/newui/jimingtaisxfx_1.gnp");
		m_jmtBitmap11[2] = UIWindows.createImage("/img/newui/jimingtaisxbdxj_1.gnp");
		m_jmtBitmap11[1] = UIWindows.createImage("/img/newui/jimingtaisxtslj_1.gnp");
		m_jmtBitmap11[0] = UIWindows.createImage("/img/newui/jimingtaisxyhdd_1.gnp");

		//神龛暗
		m_jmtBitmap16[4] = UIWindows.createImage("/img/newui/jimingtaisxtd_2.gnp");
		m_jmtBitmap16[3] = UIWindows.createImage("/img/newui/jimingtaisxfx_2.gnp");
		m_jmtBitmap16[2] = UIWindows.createImage("/img/newui/jimingtaisxbdxj_2.gnp");
		m_jmtBitmap16[1] = UIWindows.createImage("/img/newui/jimingtaisxtslj_2.gnp");
		m_jmtBitmap16[0] = UIWindows.createImage("/img/newui/jimingtaisxyhdd_2.gnp");

		m_jmtBitmap_ZBTM = UIWindows.createImage("/img/newui/zhuangbeitianming_1.gnp");//装备天命图片

		m_jmtBitmap21 = UIWindows.createImage("/img/newui/anniu_1.gnp");//大按钮
		m_jmtBitmap21_xia = UIWindows.createImage("/img/newui/anniu_1ax.gnp");//大按钮按下

		m_jmtBitmap22 = UIWindows.createImage("/img/newui/anniu_2.gnp");//小按钮
		m_jmtBitmap22_xia = UIWindows.createImage("/img/newui/anniu_2ax.gnp");//小按钮按下
	}

	/**
	 * 天命祭拜界面
	 */
	public void jimingtai01()
	{
		m_jmtFrame01 = new DWFrame(DWFrame.FRAME_TYPE_FULL, true);
		m_jmtFrame01.setClickClose(false);
		m_jmtTitle01 = new DWTitle(null, m_jmtFrame01);

		m_jmtImageBox_BT01 = new DWImageBox(m_jmtBitmap_BT01);
		m_jmtImageBox_BT01.setNearAnchor(m_jmtTitle01, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER);

		//关闭按钮
		m_jmtImageBox01 = new DWImageBox(m_jmtBitmap01);
		m_jmtImageBox01.addListener(m_back_lis01);
		m_jmtImageBox01.setNearAnchor(m_jmtTitle01, Tools.RIGHT_VCENTER, Tools.RIGHT_VCENTER);
		m_jmtImageBox01.setTouchZoomIn(20, 20);

		m_jmtBackground_jttBJ = new DWBackground(m_jmtFrame01.getShowWidth() - 20, m_jmtFrame01.getShowHeight() - 30);
		m_jmtBackground_jttBJ.setNearAnchor(m_jmtFrame01, Tools.LEFT_TOP, Tools.LEFT_TOP, 10, 20);

		//神龛
		m_jmtButton03.setNearAnchor(m_jmtFrame01, Tools.LEFT_TOP, Tools.LEFT_TOP, 50, 50);
		m_jmtButton04.setNearAnchor(m_jmtButton03, Tools.LEFT_TOP, Tools.RIGHT_TOP, 22, 0);
		m_jmtButton05.setNearAnchor(m_jmtButton04, Tools.LEFT_TOP, Tools.RIGHT_TOP, 22, 0);
		m_jmtButton06.setNearAnchor(m_jmtButton05, Tools.LEFT_TOP, Tools.RIGHT_TOP, 22, 0);
		m_jmtButton07.setNearAnchor(m_jmtButton06, Tools.LEFT_TOP, Tools.RIGHT_TOP, 22, 0);

		m_jmtButton03.addListener(m_bt11_lis);
		m_jmtButton04.addListener(m_bt12_lis);
		m_jmtButton05.addListener(m_bt13_lis);
		m_jmtButton06.addListener(m_bt14_lis);
		m_jmtButton07.addListener(m_bt15_lis);

		m_jmtButton_jttBT01 = new DWButton("", m_jmtBitmap_ZBTM);//装备天命
//		m_jmtButton_jttBT01.setDownImage(m_jmtBitmap21_xia);
		m_jmtButton_jttBT01.setNearAnchor(m_jmtFrame01, Tools.RIGHT_TOP, Tools.RIGHT_TOP, -60, 150);
		m_jmtButton_jttBT01.addListener(new DWListener() {

			public void OnDoubleClick()
			{

			}

			public void OnClick()
			{
				close((byte) 0);
				open((byte) 1);
			}
		});

		m_jmtButton_jttBT04 = new DWButton("收取天命", m_jmtBitmap21);
		m_jmtButton_jttBT04.setDownImage(m_jmtBitmap21_xia);
		switch (DWGameManager.AdpaterType) {
			case DWGameManager.AD_HIGH:
				m_jmtButton_jttBT04.setNearAnchor(m_jmtButton03, Tools.LEFT_TOP, Tools.RIGHT_BOTTOM, 100, 120);
				break;
			default:
				m_jmtButton_jttBT04.setNearAnchor(m_jmtFrame01, Tools.LEFT_TOP, Tools.LEFT_TOP, 100, 230);
				break;
		}
		m_jmtButton_jttBT04.addListener(new DWListener() {

			public void OnDoubleClick()
			{

			}

			public void OnClick()
			{
				if (m_tGrids01.m_grids.get(0).m_data != null) {
					if (DWGameManager.getInstance().m_role.m_tianming_bag.length < tianmingbagNum) {
						DWGameManager.getInstance().getSendMessage().sendTianMingShouQu();
						Tools.debugPrintln("-------------->全部收取");
					}
					else {
						DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B,
								"天命背包已满，无法收取");
					}
				}
				else {
					DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B,
							"当前没有天命，无法收取");
				}
			}
		});

		if (DWGameManager.getInstance().m_role.m_lv < 40) {
			m_jmtButton_jttBT02 = new DWButton("连续拜祭", m_jmtBitmap21_xia);
			m_jmtButton_jttBT02.setNearAnchor(m_jmtButton_jttBT04, Tools.LEFT_TOP, Tools.RIGHT_TOP, 48, 0);
			m_jmtButton_jttBT02.addListener(new DWListener() {

				public void OnDoubleClick()
				{

				}

				public void OnClick()
				{
					DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B,
							"40级开启");
				}

			});
		}
		else {
			m_jmtButton_jttBT02 = new DWButton("连续拜祭", m_jmtBitmap21);
			m_jmtButton_jttBT02.setDownImage(m_jmtBitmap21_xia);
			m_jmtButton_jttBT02.setNearAnchor(m_jmtButton_jttBT04, Tools.LEFT_TOP, Tools.RIGHT_TOP, 48, 0);
			m_jmtButton_jttBT02.addListener(new DWListener() {
				public void OnDoubleClick()
				{

				}

				public void OnClick()
				{
					if (DWGameManager.getInstance().m_role.m_gold >= DWGameManager.getInstance().m_role.m_tianming_shengJBMoney[4]) {
						final DWMessageBox mb = new DWMessageBox("提示", "将消耗金钱用于自动连续拜祭神明，是否继续？");
						mb.addListener(new DWListener() {
							public void OnDoubleClick()
							{

							}

							public void OnClick()
							{
								if (mb.getResult() == DWMessageBox.SOFTKEY_OK) {
									if (DWGameManager.getInstance().m_role.xianshiBag.length < xianshiNum) {
										DWGameManager.getInstance().getSendMessage().sendTianMingAutoJB();
										Tools.debugPrintln("-------------->连续拜祭");
									}
									else {
										DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B,
												"天命位置已满，请收取天命");
									}
								}
								else if (mb.getResult() == DWMessageBox.SOFTKEY_BACK) {

								}
								DWControlsManager.getInstance().removeControl(mb);
							}
						});
						DWControlsManager.getInstance().addControl(mb);
					}
					else {
						DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "您的金钱不足");
					}
				}
			});
		}

		m_tgTextbox_JBJG = new DWTextbox("");//动画

		m_jmtTextbox06 = new DWTextbox("命力:" + "<mark c=FF0000>" + m_tianming_mingli + "</mark>");
		m_jmtTextbox06.setNearAnchor(m_jmtFrame01, Tools.RIGHT_TOP, Tools.RIGHT_TOP, -50, 40);

		m_jmtTextbox07 = new DWTextbox("<mark c=FF0000>" + Tianming.getMoney(DWGameManager.getInstance().m_role.m_gold)
				+ "</mark>" + "金");
		m_jmtTextbox07.setNearAnchor(m_jmtTextbox06, Tools.RIGHT_TOP, Tools.RIGHT_TOP, 0, 40);

		m_tGrids01.setNearAnchor(m_jmtFrame01, Tools.HCENTER_BOTTOM, Tools.HCENTER_BOTTOM, 0, -50);
		m_tGrids01.setInterspace(m_jmtBitmap10.getHeight() / 16, m_jmtBitmap10.getHeight() / 16);

		m_jmtTextbox_TS = new DWTextbox("<mark c=FFBB11>" + "装备获得的天命可以提升攻击、防御、暴击等战斗属性" + "</mark>");
		m_jmtTextbox_TS.setNearAnchor(m_jmtFrame01, Tools.HCENTER_BOTTOM, Tools.HCENTER_BOTTOM, 0, -20);

		newTianming01();
		m_tGrids01.addListener(new DWListener() {

			public void OnDoubleClick()
			{

			}

			public void OnClick()
			{
				int index = m_tGrids01.getTouchIndex();
				tianming_index03 = index;
				if (m_tGrids01.m_grids.get(tianming_index03).m_data != null) {
					Tianming tianming = DWGameManager.getInstance().m_role.xianshiBag[tianming_index03];
					if (tianming != null) {
						tanchuang_XS(tianming);
						m_tcGrid_XS.m_data = tianming;
					}
				}
			}
		});

		m_jmtFrame01.addControl(m_jmtBackground_jttBJ);
		m_jmtFrame01.addControl(m_jmtTitle01);
		m_jmtFrame01.addControl(m_jmtImageBox_BT01);
		m_jmtFrame01.addControl(m_jmtImageBox01);
		m_jmtFrame01.addControl(m_jmtButton_jttBT01);
		m_jmtFrame01.addControl(m_jmtButton_jttBT02);
		m_jmtFrame01.addControl(m_jmtButton_jttBT04);
		m_jmtFrame01.addControl(m_tgTextbox_JBJG);
		m_jmtFrame01.addControl(m_jmtButton03);
		m_jmtFrame01.addControl(m_jmtButton04);
		m_jmtFrame01.addControl(m_jmtButton05);
		m_jmtFrame01.addControl(m_jmtButton06);
		m_jmtFrame01.addControl(m_jmtButton07);
		m_jmtFrame01.addControl(m_jmtTextbox06);
		m_jmtFrame01.addControl(m_jmtTextbox07);
		m_jmtFrame01.addControl(m_jmtTextbox_TS);
		m_jmtFrame01.addControl(m_tGrids01);
		DWControlsManager.getInstance().addControl(m_jmtFrame01);
	}

	public void newTianming01()
	{
		if (DWGameManager.getInstance().m_role.xianshiBag != null) {
			int bbsize = DWGameManager.getInstance().m_role.xianshiBag.length;
			//网格
			for (int j = 0; j < bbsize; j++) {
				Tianming tianming = DWGameManager.getInstance().m_role.xianshiBag[j];
				m_tGrids01.m_grids.get(j).m_data = tianming;
			}
		}
	}

	/**
	 * 天命装备界面
	 */
	public void jimingtai02()
	{
		m_jmtFrame02 = new DWFrame(DWFrame.FRAME_TYPE_FULL, true);
		m_jmtFrame02.setClickClose(false);
		m_jmtTitle02 = new DWTitle(null, m_jmtFrame02);

		m_jmtImageBox_BT02 = new DWImageBox(m_jmtBitmap_BT02);
		m_jmtImageBox_BT02.setNearAnchor(m_jmtTitle02, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER);

		m_jmtBackground01 = new DWBackground(m_jmtFrame02.getShowWidth() - 20, m_jmtFrame02.getShowHeight() - 30);
		m_jmtBackground01.setNearAnchor(m_jmtFrame02, Tools.LEFT_TOP, Tools.LEFT_TOP, 10, 20);

		//关闭按钮
		m_jmtImageBox02 = new DWImageBox(m_jmtBitmap01);
		m_jmtImageBox02.addListener(m_back_lis02);
		m_jmtImageBox02.setNearAnchor(m_jmtTitle02, Tools.RIGHT_VCENTER, Tools.RIGHT_VCENTER);
		m_jmtImageBox02.setTouchZoomIn(20, 20);

		m_jmtTextbox08 = new DWTextbox("命力:" + "<mark c=FF0000>" + m_tianming_mingli + "</mark>");
		m_jmtTextbox08.setNearAnchor(m_jmtFrame02, Tools.RIGHT_TOP, Tools.RIGHT_TOP, -50, 40);

		m_jmtTextbox09 = new DWTextbox("<mark c=FF0000>" + Tianming.getMoney(DWGameManager.getInstance().m_role.m_gold)
				+ "</mark>" + "金");
		m_jmtTextbox09.setNearAnchor(m_jmtTextbox08, Tools.RIGHT_TOP, Tools.RIGHT_TOP, 0, 40);

		m_jmtButton_tmtBT01 = new DWButton("返回", m_jmtBitmap21);
		m_jmtButton_tmtBT01.setDownImage(m_jmtBitmap21_xia);
		m_jmtButton_tmtBT01.setNearAnchor(m_jmtFrame02, Tools.RIGHT_BOTTOM, Tools.RIGHT_BOTTOM, -50, -50);
		m_jmtButton_tmtBT01.addListener(new DWListener() {

			public void OnDoubleClick()
			{

			}

			public void OnClick()
			{
				close((byte) 1);
				open((byte) 0);
			}
		});

		m_jmtButton_jttBT03 = new DWButton("自动吞噬", m_jmtBitmap21);
		m_jmtButton_jttBT03.setDownImage(m_jmtBitmap21_xia);
		m_jmtButton_jttBT03.setNearAnchor(m_jmtFrame02, Tools.HCENTER_BOTTOM, Tools.HCENTER_BOTTOM, -50, -50);
		m_jmtButton_jttBT03.addListener(new DWListener() {

			public void OnDoubleClick()
			{

			}

			public void OnClick()
			{
				if (DWGameManager.getInstance().m_role.m_tianming_bag.length > 1) {
					final DWMessageBox mb = new DWMessageBox("提示", "高阶以下天命将自动吞噬，是否继续？");
					mb.addListener(new DWListener() {

						public void OnDoubleClick()
						{

						}

						public void OnClick()
						{
							if (mb.getResult() == DWMessageBox.SOFTKEY_OK) {
								DWGameManager.getInstance().getSendMessage().sendTianMingAutoHB();
								Tools.debugPrintln("-------------->自动吞噬");
								DWControlsManager.getInstance().removeControl(mb);
							}
							else if (mb.getResult() == DWMessageBox.SOFTKEY_BACK) {
								DWControlsManager.getInstance().removeControl(mb);
							}
						}
					});
					DWControlsManager.getInstance().addControl(mb);
				}
				else {
					DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "天命数量不足，无法吞噬");
				}
			}
		});

		//装备位背景
		for (int i = 0; i < m_jmtGrid11.length; i++) {
			if (i < zhubeikaiqiNum) {
				m_jmtGrid11[i] = new DWGrid(m_jmtBitmap10);//已开启
			}
			else {
				m_jmtGrid11[i] = new DWGrid(m_jmtBitmap08);//未开启
			}
			m_jmtGrid11[i].setID(i);
		}

		m_jmtGrid11[0].setNearAnchor(m_jmtFrame02, Tools.LEFT_TOP, Tools.LEFT_TOP, 20, 86 + m_jmtBitmap10.getHeight());
		m_jmtGrid11[1].setNearAnchor(m_jmtGrid11[0], Tools.LEFT_BOTTOM, Tools.RIGHT_TOP, 6, -6);
		m_jmtGrid11[2].setNearAnchor(m_jmtGrid11[1], Tools.LEFT_TOP, Tools.RIGHT_TOP, 6, 0);
		m_jmtGrid11[3].setNearAnchor(m_jmtGrid11[2], Tools.LEFT_TOP, Tools.RIGHT_BOTTOM, 6, 6);
		m_jmtGrid11[4].setNearAnchor(m_jmtGrid11[3], Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 0, 6);
		m_jmtGrid11[5].setNearAnchor(m_jmtGrid11[4], Tools.RIGHT_TOP, Tools.LEFT_BOTTOM, -6, 6);
		m_jmtGrid11[6].setNearAnchor(m_jmtGrid11[5], Tools.RIGHT_TOP, Tools.LEFT_TOP, -6, 0);
		m_jmtGrid11[7].setNearAnchor(m_jmtGrid11[0], Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 0, 6);

		if (zhubeikaiqiNum >= 8) {
			m_jmtTextbox01 = new DWTextbox("已开启全部天命位",
					m_jmtBitmap10.getHeight() * 2 - 20,
					m_jmtBitmap10.getHeight() * 2 - 20);
		}
		else {
			m_jmtTextbox01 = new DWTextbox(DWGameManager.getInstance().m_role.m_tianming_nextNeedLevel + "级开启新天命位",
					m_jmtBitmap10.getHeight() * 2 - 20,
					m_jmtBitmap10.getHeight() * 2 - 20);
		}
		m_jmtTextbox01.setNearAnchor(m_jmtGrid11[0], Tools.LEFT_TOP, Tools.RIGHT_TOP, 10, 10);

		m_jmtTextbox02 = new DWTextbox("拖动天命至其它天命处即可互相吞噬");
		m_jmtTextbox02.setNearAnchor(m_jmtGrid11[2], Tools.LEFT_TOP, Tools.RIGHT_TOP, 20, 0);

		m_jmtFrame02.addControl(m_jmtBackground01);
		m_jmtFrame02.addControl(m_jmtTitle02);
		m_jmtFrame02.addControl(m_jmtImageBox_BT02);
		m_jmtFrame02.addControl(m_jmtTextbox02);
		m_jmtFrame02.addControl(m_jmtImageBox02);
		m_jmtFrame02.addControl(m_jmtTextbox01);
		m_jmtFrame02.addControl(m_jmtButton_tmtBT01);
		m_jmtFrame02.addControl(m_jmtButton_jttBT03);
		for (int i = 0; i < m_jmtGrid11.length; i++) {
			m_jmtFrame02.addControl(m_jmtGrid11[i]);
		}

		if (DWGameManager.getInstance().m_role.m_tianming_minggewei != null) {
			newGrid01();
			for (j = 0; j < zhubeikaiqiNum; j++) {
				final int index = j;
				m_jmtGrid11[j].addDragListener(new DWDragListener() {
					public void OnDrag(DWControl control)
					{
						if (control instanceof DWGrids) {
							final DWMessageBox mb = new DWMessageBox("提示", "是否装备？");
							mb.addListener(new DWListener() {

								public void OnDoubleClick()
								{

								}

								public void OnClick()
								{
									tuozhuai_index02 = m_tGrids02.getTouchIndex();
									if (mb.getResult() == DWMessageBox.SOFTKEY_OK) {
										DWGameManager.getInstance().getSendMessage().sendTianMingZhuanbei(
												(byte) m_tGrids02.getTouchIndex(),
												(byte) index);
										DWControlsManager.getInstance().removeControl(mb);
									}
									else if (mb.getResult() == DWMessageBox.SOFTKEY_BACK) {
										DWControlsManager.getInstance().removeControl(mb);
									}
								}
							});
							DWControlsManager.getInstance().addControl(mb);
						}
					}
				});
			}
		}
		m_tGrids02.setGridsImage(m_jmtBitmap10, 0, tianmingbagNum - 1);
		m_tGrids02.setGridsImage(m_jmtBitmap08, tianmingbagNum, 15);
		switch (DWGameManager.AdpaterType) {
			case DWGameManager.AD_HIGH:
				m_tGrids02.setNearAnchor(m_jmtGrid11[4], Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER, 100, 0);
				break;
			default:
				m_tGrids02.setNearAnchor(m_jmtFrame02, Tools.LEFT_TOP, Tools.LEFT_TOP, 320, 110);
				break;
		}
		m_tGrids02.setInterspace(3, 3);

		if (DWGameManager.getInstance().m_role.m_tianming_bag != null) {
			newTianming02();
			m_tGrids02.addListener(new DWListener() {

				public void OnDoubleClick()
				{

				}

				public void OnClick()
				{
					int index = m_tGrids02.getTouchIndex();
					tianming_index01 = index;
					if (tianming_index01 < tianmingbagNum) {
						for (int i = 0; i < DWGameManager.getInstance().m_role.m_tianming_bag.length; i++) {
							Tianming tianming = DWGameManager.getInstance().m_role.m_tianming_bag[i];
							if (tianming_index01 == tianming.getWhileCell()) {
								if (tianming != null) {
									tanchuang01(tianming, true);
									m_tcGrid01.m_data = tianming;
								}
							}
						}
					}
					else {
						tianmingBao_Num = index - tianmingbagNum + 1;
						final DWMessageBox mb = new DWMessageBox("提示", "开启" + tianmingBao_Num + "个天命背包需要消耗"
								+ tianmingBao_Num * 10 + "元宝，是否开启？");
						mb.addListener(new DWListener() {

							public void OnDoubleClick()
							{

							}

							public void OnClick()
							{
								if (mb.getResult() == DWMessageBox.SOFTKEY_OK) {
									DWGameManager.getInstance().getSendMessage().sendTianMingKuoBeiBao(
											(byte) tianmingBao_Num);
									DWControlsManager.getInstance().removeControl(mb);
								}
								else if (mb.getResult() == DWMessageBox.SOFTKEY_BACK) {
									DWControlsManager.getInstance().removeControl(mb);
								}
							}
						});
						DWControlsManager.getInstance().addControl(mb);
					}
				}
			});

			m_tGrids02.addDragListener(new DWDragListener() {
				public void OnDrag(DWControl control)
				{
					if (control instanceof DWGrids) {
						final DWGrids grids = (DWGrids) control;
						if (grids.getDragGird().m_data != null) {
							Tianming tianming01 = (Tianming) m_tGrids02.m_grids.get(m_tGrids02.getTouchIndex()).m_data;
							Tianming tianming02 = (Tianming) m_tGrids02.m_grids.get(grids.getDragIndex()).m_data;
							if (DWGameManager.getInstance().m_role.m_tianming_bag.length > 1) {
								if (m_tGrids02.getTouchIndex() != grids.getDragIndex()) {
									if (tianming01.qualityType > tianming02.qualityType) {//1等级大于2等级
										final DWMessageBox mb = new DWMessageBox("提示", "“<mark c="
												+ Tianming.getTianmingColor(tianming01.getQualityType())
												+ ">"
												+ tianming01.getName()
												+ "</mark>" + "”将吞噬“"
												+ "<mark c="
												+ Tianming.getTianmingColor(tianming02.getQualityType())
												+ ">"
												+ tianming02.getName()
												+ "</mark>”" + "，是否继续？");
										mb.addListener(new DWListener() {

											public void OnDoubleClick()
											{

											}

											public void OnClick()
											{
												tuozhuai_index02 = m_tGrids02.getTouchIndex();
												if (mb.getResult() == DWMessageBox.SOFTKEY_OK) {
													DWGameManager.getInstance().getSendMessage()
															.sendTianMingHebing(
																	(byte) m_tGrids02.getTouchIndex(),
																	(byte) grids.getDragIndex());
													DWControlsManager.getInstance().removeControl(mb);
												}
												else if (mb.getResult() == DWMessageBox.SOFTKEY_BACK) {
													DWControlsManager.getInstance().removeControl(mb);
												}
											}
										});
										DWControlsManager.getInstance().addControl(mb);
									}
									else if (tianming01.qualityType == tianming02.qualityType) {//1等级等于2等级
										if (tianming01.currntML >= tianming02.currntML) {//1命力大于等于2命力
											final DWMessageBox mb = new DWMessageBox("提示", "“<mark c="
													+ Tianming.getTianmingColor(tianming01.getQualityType())
													+ ">"
													+ tianming01.getName()
													+ "</mark>" + "”将吞噬“"
													+ "<mark c="
													+ Tianming.getTianmingColor(tianming02.getQualityType())
													+ ">"
													+ tianming02.getName()
													+ "</mark>”" + "，是否继续？");
											mb.addListener(new DWListener() {

												public void OnDoubleClick()
												{

												}

												public void OnClick()
												{
													tuozhuai_index02 = m_tGrids02.getTouchIndex();
													if (mb.getResult() == DWMessageBox.SOFTKEY_OK) {
														DWGameManager.getInstance().getSendMessage()
																.sendTianMingHebing(
																		(byte) m_tGrids02.getTouchIndex(),
																		(byte) grids.getDragIndex());
														DWControlsManager.getInstance().removeControl(mb);
													}
													else if (mb.getResult() == DWMessageBox.SOFTKEY_BACK) {
														DWControlsManager.getInstance().removeControl(mb);
													}
												}
											});
											DWControlsManager.getInstance().addControl(mb);
										}
										else if (tianming01.currntML < tianming02.currntML) {//1命力小于2命力
											final DWMessageBox mb = new DWMessageBox("提示", "“<mark c="
													+ Tianming.getTianmingColor(tianming02.getQualityType())
													+ ">"
													+ tianming02.getName()
													+ "</mark>" + "”将吞噬“"
													+ "<mark c="
													+ Tianming.getTianmingColor(tianming01.getQualityType())
													+ ">"
													+ tianming01.getName()
													+ "</mark>”" + "，是否继续？");
											mb.addListener(new DWListener() {

												public void OnDoubleClick()
												{

												}

												public void OnClick()
												{
													tuozhuai_index02 = m_tGrids02.getTouchIndex();
													if (mb.getResult() == DWMessageBox.SOFTKEY_OK) {
														DWGameManager.getInstance().getSendMessage()
																.sendTianMingHebing(
																		(byte) m_tGrids02.getTouchIndex(),
																		(byte) grids.getDragIndex());
														DWControlsManager.getInstance().removeControl(mb);
													}
													else if (mb.getResult() == DWMessageBox.SOFTKEY_BACK) {
														DWControlsManager.getInstance().removeControl(mb);
													}
												}
											});
											DWControlsManager.getInstance().addControl(mb);
										}
									}
									else if (tianming01.qualityType < tianming02.qualityType) {//1等级小于2等级

										final DWMessageBox mb = new DWMessageBox("提示", "“<mark c="
												+ Tianming.getTianmingColor(tianming02.getQualityType())
												+ ">"
												+ tianming02.getName()
												+ "</mark>" + "”将吞噬“"
												+ "<mark c="
												+ Tianming.getTianmingColor(tianming01.getQualityType())
												+ ">"
												+ tianming01.getName()
												+ "</mark>”" + "，是否继续？");
										mb.addListener(new DWListener() {

											public void OnDoubleClick()
											{

											}

											public void OnClick()
											{
												tuozhuai_index02 = m_tGrids02.getTouchIndex();
												if (mb.getResult() == DWMessageBox.SOFTKEY_OK) {
													DWGameManager.getInstance().getSendMessage()
															.sendTianMingHebing(
																	(byte) m_tGrids02.getTouchIndex(),
																	(byte) grids.getDragIndex());
													DWControlsManager.getInstance().removeControl(mb);
												}
												else if (mb.getResult() == DWMessageBox.SOFTKEY_BACK) {
													DWControlsManager.getInstance().removeControl(mb);
												}
											}
										});
										DWControlsManager.getInstance().addControl(mb);
									}
								}
							}
						}
					}
					else if (control instanceof DWGrid) {
						final DWGrid grid = (DWGrid) control;
						if (grid.m_data != null) {
							final DWMessageBox mb = new DWMessageBox("提示", "是否卸载？");
							mb.addListener(new DWListener() {

								public void OnDoubleClick()
								{

								}

								public void OnClick()
								{
									if (mb.getResult() == DWMessageBox.SOFTKEY_OK) {
										if (DWGameManager.getInstance().m_role.m_tianming_bag.length < tianmingbagNum) {
											for (int i = 0; i < DWGameManager.getInstance().m_role.m_tianming_minggewei.length; i++) {
												Tianming tianming = (Tianming) grid.m_data;
												DWGameManager.getInstance().getSendMessage().sendTianMingUnLoad(
														tianming.m_guid);
												Tools.debugPrintln("卸载天命");
											}
										}
										else {
											DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B,
													"天命背包已满，无法卸载");
										}
										DWControlsManager.getInstance().removeControl(mb);
									}
									else if (mb.getResult() == DWMessageBox.SOFTKEY_BACK) {
										DWControlsManager.getInstance().removeControl(mb);
									}
								}
							});
							DWControlsManager.getInstance().addControl(mb);
						}
					}
				}
			});
		}

		m_jmtFrame02.addControl(m_jmtTextbox08);
		m_jmtFrame02.addControl(m_jmtTextbox09);
		m_jmtFrame02.addControl(m_tGrids02);
		DWControlsManager.getInstance().addControl(m_jmtFrame02);
	}

	public void newTianming02()
	{
		int bbsize = DWGameManager.getInstance().m_role.m_tianming_bag.length;
		//网格
		bbsize01 = bbsize;
		for (int j = 0; j < bbsize01; j++) {
			Tianming tianming = DWGameManager.getInstance().m_role.m_tianming_bag[j];
			whi = tianming.getWhileCell();
			m_tGrids02.m_grids.get(whi).m_data = tianming;
		}
	}

	public void newGrid01()
	{
		int size = DWGameManager.getInstance().m_role.m_tianming_minggewei.length;
		for (int i = 0; i < size; i++) {
			if (m_jmtGrid11[i] != null) {

				final Tianming tianming = DWGameManager.getInstance().m_role.m_tianming_minggewei[i];

				m_jmtGrid11[tianming.getWhileCell()].m_data = tianming;

				m_jmtGrid11[tianming.getWhileCell()].addListener(new DWListener() {

					public void OnDoubleClick()
					{

					}

					public void OnClick()
					{
						int index = tianming.getWhileCell();
						tianming_index02 = index;
						if (tianming_index02 == tianming.getWhileCell()) {
							if (tianming != null) {
								tanchuang01(tianming, false);
								m_tcGrid01.m_data = tianming;
							}
						}
					}
				});
			}
		}
	}

	/**
	 * 未装备天命选项
	 */
	public DWFrame m_tcFrame01 = null;
	public DWTitle m_tcTitle01 = null;
	public DWImageBox m_tcImageBox01 = null;
	public DWBackground m_tcBackground01 = null;
	public DWBackground m_tcBackground02 = null;
	public DWButton m_tcButton01 = null;
	public DWButton m_tcButton02 = null;
	public DWTextbox m_tcTextbox01 = null;//天命阶
	public DWTextbox m_tcTextbox02 = null;//命力
	public DWTextbox m_tcTextbox05 = null;//天命类型
	public DWGrid m_tcGrid01 = null;

	public void tanchuang01(final Tianming tianming, boolean type)
	{
		if (m_tcFrame01 != null) {
			DWControlsManager.getInstance().removeControl(m_tcFrame01);
		}
		m_tcFrame01 = new DWFrame(DWGameManager.Screen_Width / 2, DWGameManager.Screen_Height / 2 + 60);
		m_tcFrame01.setNearAnchor(m_jmtFrame01, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER);

		m_tcTitle01 = new DWTitle("选项", m_tcFrame01);

		//关闭按钮
		m_tcImageBox01 = new DWImageBox(m_jmtBitmap01);
		m_tcImageBox01.addListener(m_back02_lis);
		m_tcImageBox01.setNearAnchor(m_tcTitle01, Tools.RIGHT_VCENTER, Tools.RIGHT_VCENTER);
		m_tcImageBox01.setTouchZoomIn(20, 20);

		m_tcBackground01 = new DWBackground(m_tcFrame01.getShowWidth() - 20, m_tcFrame01.getShowHeight() - 30);
		m_tcBackground01.setNearAnchor(m_tcTitle01, Tools.HCENTER_TOP, Tools.HCENTER_TOP, 0, 40);

		m_tcButton01 = new DWButton("升级", m_jmtBitmap22);
		m_tcButton01.setDownImage(m_jmtBitmap22_xia);
		m_tcButton01.addListener(new DWListener() {

			public void OnDoubleClick()
			{

			}

			public void OnClick()
			{
				DWGameManager.getInstance().getSendMessage().sendTianMingZhuRu(tianming.m_guid);
				Tools.debugPrintln("升级天命");
				DWControlsManager.getInstance().removeControl(m_tcFrame01);
			}
		});
		m_tcButton01.setNearAnchor(m_tcBackground01, Tools.LEFT_BOTTOM, Tools.LEFT_BOTTOM, 30, -30);

		if (type == true) {
			m_tcButton02 = new DWButton("装备", m_jmtBitmap22);
			m_tcButton02.setDownImage(m_jmtBitmap22_xia);
			m_tcButton02.addListener(new DWListener() {

				public void OnDoubleClick()
				{

				}

				public void OnClick()
				{
					int i = 0;
					for (; i < zhubeikaiqiNum; i++) {
						if (m_jmtGrid11[i].m_data == null) {
							break;
						}
					}
					if (i < zhubeikaiqiNum) {
						DWGameManager.getInstance().getSendMessage().sendTianMingZhuanbei((byte) tianming_index01,
								(byte) i);
						Tools.debugPrintln("装备天命");
					}
					DWControlsManager.getInstance().removeControl(m_tcFrame01);
				}
			});
		}
		else {
			m_tcButton02 = new DWButton("卸载", m_jmtBitmap22);
			m_tcButton02.setDownImage(m_jmtBitmap22_xia);
			m_tcButton02.addListener(new DWListener() {

				public void OnDoubleClick()
				{

				}

				public void OnClick()
				{
					if (DWGameManager.getInstance().m_role.m_tianming_bag.length < tianmingbagNum) {
						DWGameManager.getInstance().getSendMessage().sendTianMingUnLoad(tianming.m_guid);
						Tools.debugPrintln("卸载天命");
					}
					else {
						DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B,
								"天命背包已满，无法卸载");
					}
					DWControlsManager.getInstance().removeControl(m_tcFrame01);
				}
			});
		}

		m_tcButton02.setNearAnchor(m_tcBackground01, Tools.RIGHT_BOTTOM, Tools.RIGHT_BOTTOM, -30, -30);

		m_tcTextbox01 = new DWTextbox(Tianming.getTianmingLevel(tianming.getQualityType())
				+ DWControlTools.CHANGE_ROW
				+ "级别："
				+ tianming.getLevel()
				+ "级", 170, 100);

		m_tcTextbox05 = new DWTextbox("<mark c="
				+ Tianming.getTianmingColor(tianming.getQualityType())
				+ ">"
				+ tianming.getName()
				+ "</mark>");

		m_tcTextbox02 = new DWTextbox("增加“"
				+ Tianming.getTianMType(tianming.getPropertyType())
				+ "”"
				+ tianming.getAddAttribute()
				+ "点"
				+ DWControlTools.CHANGE_ROW
				+ "命力:"
				+ tianming.currntML
				+ "/"
				+ tianming.maxML, m_tcFrame01.getShowWidth() - 100, 100);

		m_tcGrid01 = new DWGrid(m_jmtBitmap10);

		m_tcTextbox01.setNearAnchor(m_tcBackground01, Tools.RIGHT_TOP, Tools.RIGHT_TOP, 0, 20);
		m_tcTextbox02.setNearAnchor(m_tcBackground01, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 35);
		m_tcGrid01.setNearAnchor(m_tcBackground01, Tools.LEFT_TOP, Tools.LEFT_TOP, 30, 30);
		m_tcTextbox05.setNearAnchor(m_tcGrid01, Tools.LEFT_TOP, Tools.RIGHT_TOP, 10, 10);

		m_tcFrame01.addControl(m_tcBackground01);
		m_tcFrame01.addControl(m_tcTitle01);
		m_tcFrame01.addControl(m_tcImageBox01);
		m_tcFrame01.addControl(m_tcGrid01);
		m_tcFrame01.addControl(m_tcTextbox01);
		m_tcFrame01.addControl(m_tcTextbox02);
		m_tcFrame01.addControl(m_tcTextbox05);
		m_tcFrame01.addControl(m_tcButton01);
		m_tcFrame01.addControl(m_tcButton02);
		DWControlsManager.getInstance().addControl(m_tcFrame01);
	}

	/**
	 * 返回装备天命按钮是否开启
	 * @return
	 */
	public DWButton button_open()
	{
		if (DWControlsManager.getInstance().contains(m_tcFrame01) == false) {
			return null;
		}
		else
			return m_tcButton02;
	}

	/**
	 * 返回第一个天命背包格子
	 */
	public DWGrid grids_open()
	{
		if (DWControlsManager.getInstance().contains(m_jmtFrame02) == false) {
			return null;
		}
		else
			return m_tGrids02.m_grids.get(0);

	}

	/**
	 * 天命属性显示界面
	 */
	public DWFrame m_tcFrame_XS = null;
	public DWTitle m_tcTitle_XS = null;
	public DWImageBox m_tcImageBox_XS = null;
	public DWBackground m_tcBackground_XS = null;
	public DWTextbox m_tcTextbox_XS01 = null;//天命阶
	public DWTextbox m_tcTextbox_XS02 = null;//命力
	public DWTextbox m_tcTextbox_XS03 = null;//天命类型
	public DWGrid m_tcGrid_XS = null;

	public void tanchuang_XS(final Tianming tianming)
	{
		m_tcFrame_XS = new DWFrame(DWGameManager.Screen_Width / 2, DWGameManager.Screen_Height / 2 + 60);
		m_tcFrame_XS.setNearAnchor(m_jmtFrame01, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER);

		m_tcTitle_XS = new DWTitle("选项", m_tcFrame_XS);

		//关闭按钮
		m_tcImageBox_XS = new DWImageBox(m_jmtBitmap01);
		m_tcImageBox_XS.addListener(m_back_XX_lis);
		m_tcImageBox_XS.setNearAnchor(m_tcTitle_XS, Tools.RIGHT_VCENTER, Tools.RIGHT_VCENTER);
		m_tcImageBox_XS.setTouchZoomIn(20, 20);

		m_tcBackground_XS = new DWBackground(m_tcFrame_XS.getShowWidth() - 20, m_tcFrame_XS.getShowHeight() - 30);
		m_tcBackground_XS.setNearAnchor(m_tcTitle_XS, Tools.HCENTER_TOP, Tools.HCENTER_TOP, 0, 40);

		m_tcGrid_XS = new DWGrid(m_jmtBitmap10);
		m_tcGrid_XS.setNearAnchor(m_tcBackground_XS, Tools.LEFT_TOP, Tools.LEFT_TOP, 30, 30);

		m_tcTextbox_XS01 = new DWTextbox(Tianming.getTianmingLevel(tianming.getQualityType())
				+ DWControlTools.CHANGE_ROW
				+ "级别："
				+ tianming.getLevel()
				+ "级", 170, 100);

		m_tcTextbox_XS03 = new DWTextbox("<mark c="
				+ Tianming.getTianmingColor(tianming.getQualityType())
				+ ">"
				+ tianming.getName()
				+ "</mark>");

		m_tcTextbox_XS02 = new DWTextbox("增加“"
				+ Tianming.getTianMType(tianming.getPropertyType())
				+ "”"
				+ tianming.getAddAttribute()
				+ "点"
				+ DWControlTools.CHANGE_ROW
				+ "命力:"
				+ tianming.currntML
				+ "/"
				+ tianming.maxML, m_tcFrame_XS.getShowWidth() - 100, 100);

		m_tcTextbox_XS01.setNearAnchor(m_tcBackground_XS, Tools.RIGHT_TOP, Tools.RIGHT_TOP, 0, 20);
		m_tcTextbox_XS02.setNearAnchor(m_tcBackground_XS, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 35);
		m_tcTextbox_XS03.setNearAnchor(m_tcGrid_XS, Tools.LEFT_TOP, Tools.RIGHT_TOP, 10, 10);

		m_tcFrame_XS.addControl(m_tcBackground_XS);
		m_tcFrame_XS.addControl(m_tcTitle_XS);
		m_tcFrame_XS.addControl(m_tcImageBox_XS);
		m_tcFrame_XS.addControl(m_tcGrid_XS);
		m_tcFrame_XS.addControl(m_tcTextbox_XS01);
		m_tcFrame_XS.addControl(m_tcTextbox_XS02);
		m_tcFrame_XS.addControl(m_tcTextbox_XS03);
		DWControlsManager.getInstance().addControl(m_tcFrame_XS);
	}

	/**
	 * 返回监听界面1
	 */
	private DWListener m_back_lis01 = new DWListener() {

		public void OnDoubleClick()
		{

		}

		public void OnClick()
		{
			close((byte) 0);
		}
	};

	/**
	 * 返回监听界面2
	 */
	private DWListener m_back_lis02 = new DWListener() {

		public void OnDoubleClick()
		{

		}

		public void OnClick()
		{
			close((byte) 1);
		}
	};

	/**
	 * 返回监听
	 */
	private DWListener m_back02_lis = new DWListener() {

		public void OnDoubleClick()
		{

		}

		public void OnClick()
		{
			DWControlsManager.getInstance().removeControl(m_tcFrame01);
			DWControlsManager.getInstance().removeControl(m_tcFrame_XS);
		}
	};

	/**
	 * 返回监听
	 */
	private DWListener m_back_XX_lis = new DWListener() {

		public void OnDoubleClick()
		{

		}

		public void OnClick()
		{
			DWControlsManager.getInstance().removeControl(m_tcFrame01);
			DWControlsManager.getInstance().removeControl(m_tcFrame_XS);
		}
	};

	/**
	 * 监听 神位1
	 */
	private DWListener m_bt11_lis = new DWListener() {

		public void OnDoubleClick()
		{

		}

		public void OnClick()
		{
			if (m_tianming_shengIndex == 0) {
				if (DWGameManager.getInstance().m_role.xianshiBag.length < xianshiNum) {
					if (DWGameManager.getInstance().m_role.m_gold >= DWGameManager.getInstance().m_role.m_tianming_shengJBMoney[0]) {
						DWGameManager.getInstance().getSendMessage().sendTianMingJiBai();
					}
					else {
						DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "金币不足");
					}
				}
				else {
					DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "背包已满");
				}
			}
		}
	};

	/**
	 * 监听 神位2
	 */
	private DWListener m_bt12_lis = new DWListener() {

		public void OnDoubleClick()
		{

		}

		public void OnClick()
		{
			if (m_tianming_shengIndex == 1) {
				if (DWGameManager.getInstance().m_role.xianshiBag.length < xianshiNum) {
					if (DWGameManager.getInstance().m_role.m_gold >= DWGameManager.getInstance().m_role.m_tianming_shengJBMoney[1]) {
						DWGameManager.getInstance().getSendMessage().sendTianMingJiBai();
					}
					else {
						DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "金币不足");
					}
				}
				else {
					DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "背包已满");
				}
			}
		}
	};

	/**
	 * 监听 神位3
	 */
	private DWListener m_bt13_lis = new DWListener() {

		public void OnDoubleClick()
		{

		}

		public void OnClick()
		{
			if (m_tianming_shengIndex == 2) {
				if (DWGameManager.getInstance().m_role.xianshiBag.length < xianshiNum) {
					if (DWGameManager.getInstance().m_role.m_gold >= DWGameManager.getInstance().m_role.m_tianming_shengJBMoney[2]) {
						DWGameManager.getInstance().getSendMessage().sendTianMingJiBai();
					}
					else {
						DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "金币不足");
					}
				}
				else {
					DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "背包已满");
				}
			}
		}
	};

	/**
	 * 监听 神位4
	 */
	private DWListener m_bt14_lis = new DWListener() {

		public void OnDoubleClick()
		{

		}

		public void OnClick()
		{
			if (m_tianming_shengIndex == 3) {
				if (DWGameManager.getInstance().m_role.xianshiBag.length < xianshiNum) {
					if (DWGameManager.getInstance().m_role.m_gold >= DWGameManager.getInstance().m_role.m_tianming_shengJBMoney[3]) {
						DWGameManager.getInstance().getSendMessage().sendTianMingJiBai();
					}
					else {
						DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "金币不足");
					}
				}
				else {
					DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "背包已满");
				}
			}
		}
	};

	/**
	 * 监听 神位5
	 */
	private DWListener m_bt15_lis = new DWListener() {

		public void OnDoubleClick()
		{

		}

		public void OnClick()
		{
			if (m_tianming_shengIndex == 4) {
				if (DWGameManager.getInstance().m_role.xianshiBag.length < xianshiNum) {
					if (DWGameManager.getInstance().m_role.m_gold >= DWGameManager.getInstance().m_role.m_tianming_shengJBMoney[4]) {
						DWGameManager.getInstance().getSendMessage().sendTianMingJiBai();
					}
					else {
						DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "金币不足");
					}
				}
				else {
					DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "背包已满");
				}
			}
		}
	};

	public void open(byte index)
	{
		open_state = index;
		switch (open_state) {
			case 0:
				newGrids();
				newShenkan();
				DWGameManager.getInstance().getSendMessage().sendTianMingData();
				refreshShenkan();
				jimingtai01();
				refreshMingli();
				break;
			case 1:
				frist_open_state02 = true;
				newGrid01();
				jimingtai02();
				refreshMingli();
				break;
		}
	}

	public void close(byte index)
	{
		close_state = index;
		switch (close_state) {
			case 0:
				DWControlsManager.getInstance().removeControl(m_jmtFrame01);
				DWControlsManager.getInstance().removeControl(m_tcFrame01);
				DWControlsManager.getInstance().removeControl(m_tcFrame_XS);
				m_jibaijieguo.clear();
				break;
			case 1:
				DWControlsManager.getInstance().removeControl(m_jmtFrame02);
				DWControlsManager.getInstance().removeControl(m_tcFrame01);
				DWControlsManager.getInstance().removeControl(m_tcFrame_XS);
				break;
		}
		UIWindows.getInstance().m_zhanli.open_other(DWGameManager.getInstance().m_role.m_zhanli);//战力相关
	}

	public void dispose()
	{

	}

	/**
	 * 刷新 命力,金钱
	 */
	public void refreshMingli()
	{
		if (m_jmtTextbox06 != null) {
			m_jmtTextbox06.setText("命力:" + "<mark c=FF0000>" + m_tianming_mingli + "</mark>");
		}
		if (m_jmtTextbox08 != null) {
			m_jmtTextbox08.setText("命力:" + "<mark c=FF0000>" + m_tianming_mingli + "</mark>");
		}
		if (m_jmtTextbox07 != null) {
			m_jmtTextbox07.setText("<mark c=FF0000>" + Tianming.getMoney(DWGameManager.getInstance().m_role.m_gold)
					+ "</mark>" + "金");
		}
		if (m_jmtTextbox09 != null) {
			m_jmtTextbox09.setText("<mark c=FF0000>" + Tianming.getMoney(DWGameManager.getInstance().m_role.m_gold)
					+ "</mark>" + "金");
		}
	}

	/**
	 * 初始化网格
	 */
	public void newGrids()
	{
		m_tGrids01 = new DWGrids(m_jmtBitmap10.getHeight(), m_jmtBitmap10.getWidth(), 10, 10, 1);//第一界面格子
		m_tGrids02 = new DWGrids(m_jmtBitmap08, 15, 5, 3);//第二界面格子
	}

	/**
	 * 刷新 Grid
	 */
	public void refreshGrid()
	{
		if (m_tGrids01 != null && m_tGrids02 != null) {

			m_jmtFrame01.removeControl(m_tGrids01);

			for (int i = 0; i < 10; i++) {
				if (m_tGrids01.m_grids.get(i).m_data != null) {
					m_tGrids01.m_grids.get(i).m_data = null;
				}
			}
			m_jmtFrame01.addControl(m_tGrids01);
			newTianming01();
			if (frist_open_state02 == true) {

				if (m_tGrids02 != null) {
					m_jmtFrame02.removeControl(m_tGrids02);
				}
				for (int i = 0; i < zhubeikaiqiNum; i++) {
					if (m_jmtGrid11[i] != null) {
						m_jmtFrame02.removeControl(m_jmtGrid11[i]);
					}
				}
				for (int i = 0; i < tianmingbagNum; i++) {
					if (m_tGrids02.m_grids.get(i).m_data != null) {
						m_tGrids02.m_grids.get(i).m_data = null;
					}
				}
				for (int i = 0; i < zhubeikaiqiNum; i++) {
					m_jmtGrid11[i].m_data = null;
				}
				m_jmtFrame02.addControl(m_tGrids02);
				for (int i = 0; i < zhubeikaiqiNum; i++) {
					m_jmtFrame02.addControl(m_jmtGrid11[i]);
				}
				newTianming02();
				newGrid01();
			}
		}
	}

	/**
	 * 初始化神龛
	 */
	public void newShenkan()
	{
		m_jmtButton03 = new DWButton(null, m_jmtBitmap16[4]);
		m_jmtButton04 = new DWButton(null, m_jmtBitmap16[3]);
		m_jmtButton05 = new DWButton(null, m_jmtBitmap16[2]);
		m_jmtButton06 = new DWButton(null, m_jmtBitmap16[1]);
		m_jmtButton07 = new DWButton(null, m_jmtBitmap16[0]);
	}

	/**
	 * 刷新神龛
	 */
	public void refreshShenkan()
	{
		if (m_jmtButton03 != null
				&& m_jmtButton04 != null
				&& m_jmtButton05 != null
				&& m_jmtButton06 != null
				&& m_jmtButton07 != null) {
			switch (m_tianming_shengIndex) {
				case 0:
					m_jmtButton03.setBackground(m_jmtBitmap11[4], false);
					m_jmtButton04.setBackground(m_jmtBitmap16[3], false);
					m_jmtButton05.setBackground(m_jmtBitmap16[2], false);
					m_jmtButton06.setBackground(m_jmtBitmap16[1], false);
					m_jmtButton07.setBackground(m_jmtBitmap16[0], false);
					break;
				case 1:
					m_jmtButton03.setBackground(m_jmtBitmap16[4], false);
					m_jmtButton04.setBackground(m_jmtBitmap11[3], false);
					m_jmtButton05.setBackground(m_jmtBitmap16[2], false);
					m_jmtButton06.setBackground(m_jmtBitmap16[1], false);
					m_jmtButton07.setBackground(m_jmtBitmap16[0], false);
					break;
				case 2:
					m_jmtButton03.setBackground(m_jmtBitmap16[4], false);
					m_jmtButton04.setBackground(m_jmtBitmap16[3], false);
					m_jmtButton05.setBackground(m_jmtBitmap11[2], false);
					m_jmtButton06.setBackground(m_jmtBitmap16[1], false);
					m_jmtButton07.setBackground(m_jmtBitmap16[0], false);
					break;
				case 3:
					m_jmtButton03.setBackground(m_jmtBitmap16[4], false);
					m_jmtButton04.setBackground(m_jmtBitmap16[3], false);
					m_jmtButton05.setBackground(m_jmtBitmap16[2], false);
					m_jmtButton06.setBackground(m_jmtBitmap11[1], false);
					m_jmtButton07.setBackground(m_jmtBitmap16[0], false);
					break;
				case 4:
					m_jmtButton03.setBackground(m_jmtBitmap16[4], false);
					m_jmtButton04.setBackground(m_jmtBitmap16[3], false);
					m_jmtButton05.setBackground(m_jmtBitmap16[2], false);
					m_jmtButton06.setBackground(m_jmtBitmap16[1], false);
					m_jmtButton07.setBackground(m_jmtBitmap11[0], false);
					break;
			}
		}
	}

	/**
	 * 天命背包道具的更新
	 * @param dis
	 * @throws IOException
	 */

	public void recvTianMingBug(DataInputStream dis) throws IOException
	{
		DWGameManager.getInstance().getSendMessage().unlockNetwork(GameMessage.锁_天命);
		zhubeikaiqiNum = dis.readByte(); //天命装备栏开启的数
		byte zhubeiLSize = dis.readByte(); //天命装备栏装备了天命数
		Tianming[] zhuanbeiBag = new Tianming[zhubeiLSize];
		for (int i = 0; i < zhubeiLSize; i++) {
			Tianming tm = new Tianming();
			tm.setM_guid(dis.readLong()); //id
			tm.setLevel(dis.readByte()); //等级
			tm.setName(dis.readUTF()); //名字
			tm.setQualityType(dis.readByte());//天命品质
			tm.setPropertyType(dis.readByte()); //类型
			tm.setAddAttribute(dis.readInt());
			tm.setWhileCell(dis.readByte()); //显示第几位
			tm.currntML = dis.readInt(); //当前命力
			tm.maxML = dis.readInt(); //最大命力
			zhuanbeiBag[i] = tm;
		}

		tianmingbagNum = dis.readByte(); //
		byte tianmingbaghave = dis.readByte();
		Tianming[] baghave = new Tianming[tianmingbaghave];
		for (int i = 0; i < tianmingbaghave; i++) {
			Tianming tm = new Tianming();
			tm.setM_guid(dis.readLong()); //id
			tm.setLevel(dis.readByte()); //等级
			tm.setName(dis.readUTF()); //名字
			tm.setQualityType(dis.readByte());//天命品质
			tm.setPropertyType(dis.readByte()); //类型
			tm.setAddAttribute(dis.readInt());
			tm.setWhileCell(dis.readByte()); //显示第几位
			tm.currntML = dis.readInt(); //当前命力
			tm.maxML = dis.readInt(); //最大命力
			baghave[i] = tm;
		}

		DWGameManager.getInstance().m_role.m_tianming_minggewei = zhuanbeiBag;
		DWGameManager.getInstance().m_role.m_tianming_bag = baghave;

		newGrid01();
		for (int i = 0; i < zhubeikaiqiNum; i++) {
			if (m_jmtGrid11[i] != null) {
				m_jmtFrame02.removeControl(m_jmtGrid11[i]);
				m_jmtGrid11[i].m_data = null;
				m_jmtFrame02.addControl(m_jmtGrid11[i]);
			}
		}

		refreshGrid();
		refreshMingli();
		refreshShenkan();
	}

	/**
	 * 开启天命所需数据
	 * @param dis
	 * @throws IOException
	 */
	public void recvTianMingData(DataInputStream dis) throws IOException
	{
		DWGameManager.getInstance().getSendMessage().unlockNetwork(GameMessage.锁_天命);
		m_tianming_shengIndex = (byte) (dis.readByte() - 1);
		m_tianming_mingli = dis.readInt();

		refreshMingli();
		refreshShenkan();
		refreshGrid();
	}

	/**
	 * 开启天命拜神花费
	 * @param dis
	 * @throws IOException
	 */
	public void recvTianMingJiBaiMoney(DataInputStream dis) throws IOException
	{
		DWGameManager.getInstance().getSendMessage().unlockNetwork(GameMessage.锁_天命);
		for (int i = 0; i < 5; i++) {
			DWGameManager.getInstance().m_role.m_tianming_shengJBMoney[i] = dis.readInt();
		}
		DWGameManager.getInstance().m_role.m_tianming_nextNeedLevel = dis.readInt();
		for (int i = 0; i < zhubeikaiqiNum; i++) {
			if (m_jmtGrid11[i] != null) {
				m_jmtFrame02.removeControl(m_jmtGrid11[i]);
				m_jmtGrid11[i].m_data = null;
				m_jmtFrame02.addControl(m_jmtGrid11[i]);
			}
		}
//		newGrid01();
	}

	/**
	 * 天命所有操作放回
	 * @param dis
	 * @throws IOException
	 */
	public void recvTianMingState(DataInputStream dis) throws IOException
	{
		DWGameManager.getInstance().getSendMessage().unlockNetwork(GameMessage.锁_天命);
		dis.readInt(); //指令号
		byte state = dis.readByte(); //返回的各种状况0失败1成功2其他3等级不足4没有家族5元宝不足6背包满，７金币不足
		switch (state) {
			case 0:
				DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "失败！");
				break;
			case 1:
				break;
			case 2:
				DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "其他错误！");
				break;
			case 3:
				DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "等级不足！");
				break;
			case 4:
				DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "没有家族！");
				break;
			case 5:
				DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "元宝不足！");
				break;
			case 6:
				DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "背包已满！");
				break;
			case 7:
				DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "金币不足！");
				break;
		}
	}

	/**
	 * 卸载天命
	 * @param dis
	 * @throws IOException
	 */
	public void recvTianMingUnLoadTM(DataInputStream dis) throws IOException
	{
		DWGameManager.getInstance().getSendMessage().unlockNetwork(GameMessage.锁_天命);
		byte state = dis.readByte(); //1成功，0失败
		switch (state) {
			case 1:
				long tiamMing_id = dis.readLong(); //卸载的天命的id
				refreshGrid();
				refreshShenkan();
				refreshMingli();
				break;
		}
	}

	/**
	 * 扩充天命背包
	 * @param dis
	 * @throws IOException
	 */
	public void recvTianMingKuoBeiBao(DataInputStream dis) throws IOException
	{
		DWGameManager.getInstance().getSendMessage().unlockNetwork(GameMessage.锁_天命);
		byte state = dis.readByte(); //1成功，0失败
		switch (state) {
			case 0:
				DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "失败！");
				break;
			case 1:
				byte num = dis.readByte();
				tianmingbagNum = num;
				m_tGrids02.setGridsImage(m_jmtBitmap10, 0, tianmingbagNum - 1);
				m_tGrids02.setGridsImage(m_jmtBitmap08, tianmingbagNum, 10);
				break;
			case 2:
				DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, "元宝不足！");
				break;
		}
	}

	private CopyOnWriteArrayList<String> m_jibaijieguo = new CopyOnWriteArrayList<String>();
//	private int m_jibai_index = 0;
	private int m_jibai_y = 0;

	/**
	 * 祭拜结果
	 * @param dis
	 * @throws IOException
	 */
	public void recvTianMingJiBaiJieGuo(DataInputStream dis) throws IOException
	{
		DWGameManager.getInstance().getSendMessage().unlockNetwork(GameMessage.锁_天命);
		byte qualityType = dis.readByte(); //天命品阶
		String name = dis.readUTF();//天命名称

		String text = "";
		switch (qualityType) {
			case 0:
				text = "获得" + "<mark c=FF0000>1</mark>" + "点命力";
				break;
			case 1:
				text = "获得低阶天命" + "\"<mark c=" + Tianming.getTianmingColor(1) + ">" + name + "</mark>\"";
				break;
			case 2:
				text = "获得中阶天命" + "\"<mark c=" + Tianming.getTianmingColor(2) + ">" + name + "</mark>\"";
				break;
			case 3:
				text = "获得高阶天命" + "\"<mark c=" + Tianming.getTianmingColor(3) + ">" + name + "</mark>\"";
				break;
			case 4:
				text = "获得神阶天命" + "\"<mark c=" + Tianming.getTianmingColor(4) + ">" + name + "</mark>\"";
				break;
		}
		m_jibaijieguo.add(text);
	}

	/**
	 * 祭拜界面接收数据
	 * @param dis
	 * @throws IOException
	 */
	public void recvTianMingDaKai(DataInputStream dis) throws IOException
	{
		DWGameManager.getInstance().getSendMessage().unlockNetwork(GameMessage.锁_天命);
		xianshiNum = dis.readByte();
		byte tianmingbagNum = dis.readByte(); //天命缓存栏天命个数
		Tianming[] tianmingbag = new Tianming[tianmingbagNum];
		for (int i = 0; i < tianmingbagNum; i++) {
			Tianming tm = new Tianming();
			tm.setM_guid(dis.readLong()); //id
			tm.setLevel(dis.readByte()); //等级
			tm.setName(dis.readUTF()); //名字
			tm.setQualityType(dis.readByte());//天命品质
			tm.setPropertyType(dis.readByte()); //类型
			tm.setAddAttribute(dis.readInt()); //增加属性值
			tm.currntML = dis.readInt(); //当前命力
			tm.maxML = dis.readInt(); //最大命力
			tianmingbag[i] = tm;
		}
		DWGameManager.getInstance().m_role.xianshiBag = tianmingbag;

		refreshGrid();
		refreshShenkan();
		refreshMingli();
		for (int i = 0; i < zhubeikaiqiNum; i++) {
			if (m_jmtGrid11[i] != null) {
				m_jmtFrame02.removeControl(m_jmtGrid11[i]);
				m_jmtGrid11[i].m_data = null;
				m_jmtFrame02.addControl(m_jmtGrid11[i]);
			}
		}
		newGrid01();
	}

//	public int [] m_tianming_shengJBMoney= new int[5];	 //拜神费
	private byte m_tianming_shengIndex; //显灵神位
	private int m_tianming_mingli; //当前角色的命力
//	private int m_tianming_nextNeedLevel; //开启新天命位需要的级别
	private static byte zhubeikaiqiNum; //天命装备栏开启的数
	private static byte tianmingbagNum; //天命背包栏开启的数
	private static byte xianshiNum; //天命缓存栏天命个数

	public void logic()
	{
		if (m_jmtFrame01 != null && DWControlsManager.getInstance().contains(m_jmtFrame01)) {
			if (m_jibaijieguo != null && m_jibaijieguo.size() > 0) {
				if (m_jibai_y == 0) {
					m_tgTextbox_JBJG.setText(m_jibaijieguo.get(0));
				}
				if (m_jibai_y >= 30) {
					m_jibai_y = 0;
					m_jibaijieguo.remove(0);
					m_tgTextbox_JBJG.setText("");
					m_tgTextbox_JBJG.setNearAnchor(m_jmtButton_jttBT02, Tools.LEFT_TOP, Tools.RIGHT_TOP, 48, 15);
				}
				else {
					m_tgTextbox_JBJG.setNearAnchor(m_jmtButton_jttBT02, Tools.LEFT_TOP, Tools.RIGHT_TOP, 48,
							15 - m_jibai_y);
					m_jibai_y += 8;
				}
			}
		}
	}
}
